#ifndef _SEARCHHANDLER_H_
#define _SEARCHHANDLER_H_

/*
 * =====================================================================================
 *
 *       Filename:  searchHandler.h    
 *        
 *
 *         Author:  Alvin Chan (A0097379H), chanwh.alvin@gmail.com
 *   Organization:  NUS, SoC
 *
 * =====================================================================================
 */

/**************************************************************************
 * This header file describes the searchHandler class              
 * It takes in user input and performs searches based on the tasks already in the system     
 * The class is able to perform searches based on individual words, multiple search attributes
 * and to check if a slot is available or occupied
 **************************************************************************/

/*
Expected operation parameters:

search /t meeting /l nus

1
_______Task[15]_______
cs2103 meeting
About: review issues and bugs
At:    nus utown
With:  cs2103 project group

Priority: LOW    
Status: UNFINISHED
----------------------
From 1000 06/11/2013
till 1200 06/11/2013
----------------------
*/


#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <ctime>
#include <time.h>
#include <algorithm>
#include "FloatingTask.h"
#include "DeadlineTask.h"
#include "TimedTask.h"
#include "CommonConstant.h"

using namespace std;

//@author A0097379H
class searchHandler{

public:
	searchHandler();
	string executeCommand(string, vector<FloatingTask*>);

private:
	enum COMMAND_TYPE{
		 SEARCH, SEARCH_TASK, SEARCH_LOCATION, SEARCH_PERSON, SEARCH_DESCRIPTION, SEARCH_START_TIME, SEARCH_TIME, SEARCH_DATE, SEARCH_AVAILABLE, SEARCH_PRIORITY, SEARCH_FINISHED, EXIT, INVALID
	};
	string extractCommand(string);
	searchHandler::COMMAND_TYPE determineCommandType(string);

	vector <FloatingTask*> searchAll(vector<FloatingTask*>&, string);
	vector <FloatingTask*> searchName(vector<FloatingTask*>&, string); 
	vector <FloatingTask*> searchLocation(vector<FloatingTask*>&, string); 
	vector <FloatingTask*> searchPerson(vector<FloatingTask*>&, string); 
	vector <FloatingTask*> searchDescription(vector<FloatingTask*>&, string); 
	vector <FloatingTask*> searchTime(vector<FloatingTask*>&, string); //search both start and end time fields for matches
	vector <FloatingTask*> searchDate(vector<FloatingTask*>&, string); //search both start and end date fields for matches
	vector <FloatingTask*> searchPriority(vector<FloatingTask*>&, string);
	vector <FloatingTask*> searchFinished(vector<FloatingTask*>&, string);
	string searchAvailableSlot(vector<FloatingTask*>&, string); //search for available time slot amongst all tasks

	void checkStandardCommand(string&, string&, string&, int&); 
	bool checkDateCommand(string&, string&, string&, int&); //check if command is a date search
	bool checkAvailabilityCommand(string&, string&, string&, int&); //check if command is a availability search
	bool checkTimeClash(string, string, time_t, time_t);
	string extractWord(string&);
	int convertStringToInt(string);
	string lowerCase(string parameter);

	static const string MESSAGE_SEARCH_NO_RESULT;
	static const string	MESSAGE_SEARCH_VECTOR_EMPTY;
	static const string MESSAGE_INVALID_COMMAND;
	static const string MESSAGE_INVALID_TIME_FORMAT;
	static const string MESSAGE_TIME_SLOT_AVAILABLE;
	static const string MESSAGE_TIME_SLOT_NOT_AVAILABLE;
};

#endif